home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DKBSRC.ARJ / VECTOR.H < prev    next >
C/C++ Source or Header  |  1991-05-04  |  4KB  |  96 lines

  1. /*****************************************************************************
  2. *
  3. *                                    vector.h
  4. *
  5. *   from DKBTrace (c) 1990  David Buck
  6. *
  7. *  This module contains macros to perform operations on vectors.
  8. *
  9. * This software is freely distributable. The source and/or object code may be
  10. * copied or uploaded to communications services so long as this notice remains
  11. * at the top of each file.  If any changes are made to the program, you must
  12. * clearly indicate in the documentation and in the programs startup message
  13. * who it was who made the changes. The documentation should also describe what
  14. * those changes were. This software may not be included in whole or in
  15. * part into any commercial package without the express written consent of the
  16. * author.  It may, however, be included in other public domain or freely
  17. * distributed software so long as the proper credit for the software is given.
  18. *
  19. * This software is provided as is without any guarantees or warranty. Although
  20. * the author has attempted to find and correct any bugs in the software, he
  21. * is not responsible for any damage caused by the use of the software.  The
  22. * author is under no obligation to provide service, corrections, or upgrades
  23. * to this package.
  24. *
  25. * Despite all the legal stuff above, if you do find bugs, I would like to hear
  26. * about them.  Also, if you have any comments or questions, you may contact me
  27. * at the following address:
  28. *
  29. *     David Buck
  30. *     22C Sonnet Cres.
  31. *     Nepean Ontario
  32. *     Canada, K2H 8W7
  33. *
  34. *  I can also be reached on the following bulleton boards:
  35. *
  36. *     OMX              (613) 731-3419
  37. *     Mystic           (613) 596-4249  or  (613) 596-4772
  38. *
  39. *  Fidonet:   1:163/109.9
  40. *  Internet:  dbuck@ccs.carleton.ca
  41. *  The "You Can Call Me RAY" BBS    (708) 358-5611
  42. *
  43. *  IBM Port by Aaron A. Collins. Aaron may be reached on the following BBS'es:
  44. *
  45. *     The "You Can Call Me RAY" BBS (708) 358-5611
  46. *     The Information Exchange BBS  (708) 945-5575
  47. *
  48. *****************************************************************************/
  49.  
  50.  
  51. /* Misc. Vector Math Macro Definitions */
  52.  
  53. extern DBL VTemp;
  54.  
  55. /* Vector Add */
  56. #define VAdd(a, b, c) {(a).x=(b).x+(c).x;(a).y=(b).y+(c).y;(a).z=(b).z+(c).z;}
  57.  
  58. /* Vector Subtract */
  59. #define VSub(a, b, c) {(a).x=(b).x-(c).x;(a).y=(b).y-(c).y;(a).z=(b).z-(c).z;}
  60.  
  61. /* Scale - Multiply Vector by a Scalar */
  62. #define VScale(a, b, k) {(a).x=(b).x*(k);(a).y=(b).y*(k);(a).z=(b).z*(k);}
  63.  
  64. /* Inverse Scale - Divide Vector by a Scalar */
  65. #define VInverseScale(a, b, k) {(a).x=(b).x/(k);(a).y=(b).y/(k);(a).z=(b).z/(k);}
  66.  
  67. /* Dot Product - Gives Scalar angle (a) between two vectors (b) and (c) */
  68. #define VDot(a, b, c) {a=(b).x*(c).x+(b).y*(c).y+(b).z*(c).z;}
  69.  
  70. /* Cross Product - returns Vector (a) = (b) x (c) 
  71.    WARNING:  a must be different from b and c.*/
  72. #define VCross(a,b,c) {(a).x=(b).y*(c).z-(b).z*(c).y; \
  73.                        (a).y=(b).z*(c).x-(b).x*(c).z; \
  74.                        (a).z=(b).x*(c).y-(b).y*(c).x;}
  75.  
  76. /* Evaluate - returns Vector (a) = Multiply Vector (b) by Vector (c) */
  77. #define VEvaluate(a, b, c) {(a).x=(b).x*(c).x;(a).y=(b).y*(c).y;(a).z=(b).z*(c).z;}
  78.  
  79. /* Square a Vector */
  80. #define    VSqr(a) {(a).x*(a).x;(a).y*(a).y;(a).z*(a).z;}
  81.  
  82. /* Simple Scalar Square Macro */
  83. #define    Sqr(a)    (a*a)
  84.  
  85. /* Square a Vector (b) and Assign to another Vector (a) */
  86. #define VSquareTerms(a, b) {(a).x=(b).x*(b).x;(a).y=(b).y*(b).y;(a).z=(b).z*(b).z;}
  87.  
  88. /* Vector Length - returs Scalar Euclidean Length (a) of Vector (b) */
  89. #define VLength(a, b) {a=sqrt((b).x*(b).x+(b).y*(b).y+(b).z*(b).z);}
  90.  
  91. /* Normalize a Vector - returns a vector (length of 1) that points at (b) */
  92. #define VNormalize(a,b) {VTemp=sqrt((b).x*(b).x+(b).y*(b).y+(b).z*(b).z);(a).x=(b).x/VTemp;(a).y=(b).y/VTemp;(a).z=(b).z/VTemp;}
  93.  
  94. /* Compute a Vector (a) Halfway Between Two Given Vectors (b) and (c) */
  95. #define VHalf(a, b, c) {(a).x=0.5*((b).x+(c).x);(a).y=0.5*((b).y+(c).y);(a).z=0.5*((b).z+(c).z);}
  96.